/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package JavaBeans;

import java.io.Serializable;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Brian
 *
 * This class stores the values of the object students
 */

public class User implements Serializable
{

    
    private String password;
    private String confirmpassword;
    private String email;
    private int ssn;
    private String phone;
    private String address;
    private int zipcode;
    private String lastname;
    private String firstname;
    private String id;
    private String credit;
    private double hourly;
    private char role;

    public char getRole() {
        return role;
    }

    public void setRole(char role) {
        this.role = role;
    }

    public String getCredit() {
        return credit;
    }

    public void setCredit(String credit) {
        this.credit = credit;
    }
    public double getHourly() {
        return hourly;
    }

    public void setHourly(double hourly) {
        this.hourly = hourly;
    }
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }
    

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
    
    public int getSsn() {
        return ssn;
    }

    public void setSsn(int ssn) {
        this.ssn = ssn;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getFirstname() {
        return firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public int getZipcode() {
        return zipcode;
    }

    public void setZipcode(int zipcode) {
        this.zipcode = zipcode;
    }
    

    
    /*
     * null constructor
     */
    public User ()
    {

    }
/*
 * returns the String email as a String
 */

    public String getEmail() {
        return email;
    }


/*
 * returns the password as a String
 */
    public String getPassword() {
        return password;
    }
/*
 * returns the confirmpassword as a String
 */
    public String getConfirmpassword() {
        return confirmpassword;
    }

/*
 * sets the email address
 */
    public void setEmail(String email) {
        this.email = email;
    }

    /*
     *
     */


/*
 * sets the password of the user
 */
    public void setPassword(String password) {
        this.password = password;
    }
/*
 *
 * sets the confirmpassword of the user
 */
    public void setConfirmpassword(String confirmpassword) {
        this.confirmpassword = confirmpassword;
    }



    /*
     * checks if the password entered is valid
     * it returns true if the password is valid
     * otherwise, it returns false
     *
     */
    public boolean isValidPassword()
    {
        Pattern pattern;
	Matcher matcher;
        if (password.length()>15||confirmpassword.length()>15)
            return false;
       
        try{
                String b="((?=.*\\d)(?=.*[a-z]).{8,15})";
                pattern = Pattern.compile(b);
                matcher = pattern.matcher(password);

                return matcher.matches();
        }
        catch (Exception e)
        {
            return false;
        }
    }

 /**
 *
 * validEmail helps to check if the email is in the right format
 * @return true the email entered by the user is in the right format or otherwise
 * this method will return no.
 */
    public boolean isValidEmail()
    {
        if (email.length()>30)
            return false;
        Pattern pattern;
        Matcher matcher;
        String EMAIL_PATTERN = "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
        pattern = Pattern.compile(EMAIL_PATTERN);
        matcher = pattern.matcher(email);

        return matcher.matches();
    }

   /*
     * checks if all the fields entered is valid
     * it returns true if all the fields are valid
     * otherwise, it returns false
     *
     */
        public boolean isValid()
    {
        if (isValidEmail()&&isValidPassword())
            return true;
        return false;
    }
        
    public boolean isValidid() {
        if (id.length()<5||id.length()>10)
            return false;
        Pattern pattern;
        Matcher matcher;
        String id = "([A-Za-z0-9]++)";
        pattern = Pattern.compile(id);
        matcher = pattern.matcher(id);
        return matcher.matches();
    }
}
